package com.OA.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.OA.dao.KnowledgeQKMapper;
import com.OA.entity.Knowledge;
import com.OA.entity.MenuQK;
import com.OA.entity.RoleQK;
import com.OA.entity.Thematic;
import com.OA.service.KnowledgeQKService;
import com.OA.util.Page;

@Service
public class KnowledgeQKServiceImpl implements KnowledgeQKService {
	@Autowired
	private KnowledgeQKMapper knowledgeQKMapper;
	//________________________________________________________________________________专题管理——————————————————————
	/**
	 * 分页查询商品列表
	 * @param page
	 * @param searchPname
	 * @param serachCname
	 * @return
	 */
	public Page<Thematic> loadthematicByPage(Page<Thematic>  page,String searchthenumber, String serachthename){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ispageNO", 1);
		map.put("beginIndex", (page.getPageNo() - 1) * page.getPageSize());
		map.put("pageSize", page.getPageSize());
		map.put("searchthenumber","%"+searchthenumber+"%" );
		map.put("serachthename","%"+serachthename+"%" );
		List<Thematic> list = knowledgeQKMapper.loadthematicByPage(map);
		page.setPageNo(page.getPageNo());
		page.setPageSize(page.getPageSize());
		page.setRows(list);
		long total = knowledgeQKMapper.selectThematicByAllCount();
		page.setTotal(total);
		return page ;
	}	
	/**
	 * 添加专题
	 * 
	 * @param thematic
	 */
	public void saveloadByThematic(Thematic thematic) {
		knowledgeQKMapper.saveloadByThematic(thematic);
	}

	/**
	 * 修改专题
	 * 
	 * @param thematic
	 */
	public void updateByThematic(Thematic thematic) {
		knowledgeQKMapper.updateByThematic(thematic);
	}
	/**
	 * 通过主键加载专题对象
	 */
	public Thematic loadCartBytheId(int  theid){
		return knowledgeQKMapper.loadCartBytheId(theid);
	}
	
	/***
	 * 根据ID删除数据
	 * @param Theid
	 */
	public void remove(Integer theid){
		knowledgeQKMapper.remove(theid);
	}
	
	/**
	 * 通过当前用户登录id加载他拥有的菜单权限
	 * @param uid
	 * @return
	 */
	public List<MenuQK> loadMenusByUserId(int uid) {
		return knowledgeQKMapper.loadMenusByUserId(uid);
	}
	
	/**
	 * 插入菜单表
	 * @param menu
	 */
	public void insertMenuTable(MenuQK menu){
		 knowledgeQKMapper.insertMenuTable(menu);
	}
	/**
	 * 通过菜单的名字查询菜单的ID
	 * @param menuname
	 * @return
	 */
	public int loadMenuById(String menuname){
		return knowledgeQKMapper.loadMenuById(menuname);
	}
	/**
	 * 查询角色表
	 * @return
	 */
	public List<RoleQK>loadRole(){
		return knowledgeQKMapper.loadRole();
	}
	/**
	 * 插入角色菜单表
	 * @param menuid
	 * @param roleid
	 */
	public void insertRoleMenu(int roleid,int menuid){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleid", roleid);
		map.put("menuid",menuid );
		knowledgeQKMapper.insertRoleMenu(map);
	}
	
	/**
	 * 通过ID获取菜单信息
	 * @param menuid
	 * @return
	 */
	public List<MenuQK> loadmenuid(int menuid){
		return knowledgeQKMapper.loadmenuid(menuid);
	}
	
	/**
	 * 修改节点信息
	 * @param menu
	 */
	public void updataMenuid(MenuQK menu){
		knowledgeQKMapper.updataMenuid(menu);
	}
	
	/**
	 * 删除节点信息
	 * @param menu
	 */
	public void deleteMenuid(int menuid){
		knowledgeQKMapper.deleteMenuid(menuid);
	}
	/**
	 * 删除节点关联表信息
	 * @param menuid
	 */
	public void delteRolemenuMenuid(int  menuid){
		knowledgeQKMapper.delteRolemenuMenuid(menuid);
	}
	/**
	 * 分页查询所以知识
	 * @param page
	 * @return
	 */
	public Page<Knowledge> loadKnowledgeByPage(Page<Knowledge>  page){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ispageNO", 1);
		map.put("beginIndex", (page.getPageNo() - 1) * page.getPageSize());
		map.put("pageSize", page.getPageSize());
		List<Knowledge> list = knowledgeQKMapper.loadKnowledgeByPage(map);
		page.setPageNo(page.getPageNo());
		page.setPageSize(page.getPageSize());
		page.setRows(list);
		long total = knowledgeQKMapper.selectKnowledgeByAllCount();
		page.setTotal(total);
		return page ;
	}
	/**
	 * 分页查询我的知识
	 * @param page
	 * @return
	 */
	public Page<Knowledge> loadmyKnowledgeByPage(Page<Knowledge>  page){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ispageNO", 1);
		map.put("beginIndex", (page.getPageNo() - 1) * page.getPageSize());
		map.put("pageSize", page.getPageSize());
		List<Knowledge> list = knowledgeQKMapper.loadmyKnowledgeByPage(map);
		page.setPageNo(page.getPageNo());
		page.setPageSize(page.getPageSize());
		page.setRows(list);
		long total = knowledgeQKMapper.selectmyKnowledgeByAllCount();
		page.setTotal(total);
		return page ;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
//	/**
//	 * 查询专题数据
//	 */
//	@Override
//	public Page<Thematic> selectThematicByAllPage(int pageNo, int pageSize) {
//		System.out.println("专题管理selectThematicByAllPage服务层");
//		Map<String, Object> map = new HashMap<String, Object>();
//		map.put("ispageNO", 1);
//		map.put("beginIndex", (pageNo - 1) * pageSize);
//		map.put("pageSize", pageSize);
//		List<Thematic> list = knowledgeQKMapper.selectThematicByAllPage(map);
//		Page<Thematic> page = new Page<Thematic>();
//		page.setPageNo(pageNo);
//		page.setPageSize(pageSize);
//		page.setRows(list);
//		return page;
//	}
}
